package com.fenghongzhang.day007;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private TabLayout tb;
    private ViewPager vp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        tb = (TabLayout) findViewById(R.id.tb);
        vp = (ViewPager) findViewById(R.id.vp);

        //1,数据源
        List<Fragment> list = new ArrayList<>();
        list.add(new OneFragment());
        list.add(new TwoFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());
        list.add(new ThreeFragment());

        //数据-> 标题的数据源
        List<String> title = new ArrayList<>();
        title.add("新闻");
        title.add("游戏");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");
        title.add("娱乐");

        //2,适配器
        FragmentAdapter fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(),list,title);
        vp.setAdapter(fragmentAdapter);

        //链接
        tb.setupWithViewPager(vp);

    }
}
